package com.mall507.fivepeaks.util;

import android.os.Environment;

import com.mall507.comn.model.User;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author
 * @version 1.0
 * @date 2017/8/8
 */

public class Util extends com.hzh.frame.util.Util{

    // 判断SD卡是否存在
    public static boolean isThereSD() {
        String state = Environment.getExternalStorageState();
        if (state.equals(Environment.MEDIA_MOUNTED)) {
            return true;
        } else {
            return false;
        }
    }
    /**
     * 自适应 转K
     * */
    public static String toK(double come){
        if(come<1000){
            return come+"";
        }else{
            return doubleFormat((come/1000))+"k";
        }
    }
    /**
     * 判断是否是数字[0-9]并且能被X整除
     * @param x 被整除数
     * @param content 需要判断的数值
     * */
    public static boolean isNumberX(int x,String content) {
        Pattern p = Pattern.compile("[0-9]*");
        Matcher m = p.matcher(content);
        if (m.matches()) {
            if (Integer.parseInt(content) % x == 0) {
                return true;
            }
        }
        return false;
    }

    private static long lastClickTime;
    public synchronized static boolean isFastClick() {
        long time = System.currentTimeMillis();
        if (time - lastClickTime < 500) {
            return true;
        }
        lastClickTime = time;
        return false;
    }

    /**
     * 判断用户登录状态
     * @param user 登录用户
     * @return 登录成功/未登录
     * */
    public static boolean IfUserLoginState(User user){
        if (user == null || user.getId() == null) {
            return false;
        }else{
            return true;
        }
    }

}